<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        
        <meta name="author" content="隐星魂 (Roy.Sun)">
        
        <link rel="shortcut icon" href="../../../img/favicon.ico">
        <title>06-微行电子H750开发板上手指南 - 玄武操作系统</title>
        <link href="../../../css/bootstrap.min.css" rel="stylesheet">
        <link href="../../../css/font-awesome.min.css" rel="stylesheet">
        <link href="../../../css/base.css" rel="stylesheet">
        <link rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/10.0.3/styles/color-brewer.min.css">

        <script src="../../../js/jquery-1.10.2.min.js" defer></script>
        <script src="../../../js/bootstrap.min.js" defer></script>
        <script src="https://cdn.staticfile.org/highlight.js/10.0.3/highlight.min.js"></script>
        <script>hljs.initHighlightingOnLoad();</script> 
    </head>

    <body>
        <div class="navbar fixed-top navbar-expand-lg navbar-dark bg-primary">
            <div class="container">
                <a class="navbar-brand" href="../../..">玄武操作系统</a>
                <!-- Expander button -->
                <button type="button" class="navbar-toggler" data-toggle="collapse" data-target="#navbar-collapse">
                    <span class="navbar-toggler-icon"></span>
                </button>

                <!-- Expanded navigation -->
                <div id="navbar-collapse" class="navbar-collapse collapse">
                        <!-- Main navigation -->
                        <ul class="nav navbar-nav">
                            <li class="navitem">
                                <a href="../../.." class="nav-link">主页</a>
                            </li>
                            <li class="navitem">
                                <a href="../../../License/" class="nav-link">开源协议</a>
                            </li>
                            <li class="dropdown active">
                                <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">快速开发指南 <b class="caret"></b></a>
                                <ul class="dropdown-menu">
                                    
  <li class="dropdown-submenu">
    <a href="#" class="dropdown-item">STM32</a>
    <ul class="dropdown-menu">
            
<li>
    <a href="../01-Envsetup-Guide/" class="dropdown-item">01-开发环境搭建指南</a>
</li>
            
<li>
    <a href="../02-atkh743/" class="dropdown-item">02-正点原子阿波罗H743开发板上手指南</a>
</li>
            
<li>
    <a href="../03-fk429m/" class="dropdown-item">03-反客F429核心板上手指南</a>
</li>
            
<li>
    <a href="../04-atkf103core/" class="dropdown-item">04-正点原子F103核心板上手指南</a>
</li>
            
<li>
    <a href="../05-atkf407core/" class="dropdown-item">05-正点原子F407核心板上手指南</a>
</li>
            
<li>
    <a href="./" class="dropdown-item active">06-微行电子H750开发板上手指南</a>
</li>
            
<li>
    <a href="../07-Project-From-Scratch-Guide/" class="dropdown-item">07-自定义工程配置指南</a>
</li>
    </ul>
  </li>
                                    
  <li class="dropdown-submenu">
    <a href="#" class="dropdown-item">GD32</a>
    <ul class="dropdown-menu">
            
<li>
    <a href="../../gd32/01-Envsetup-Guide/" class="dropdown-item">01-开发环境搭建指南</a>
</li>
            
<li>
    <a href="../../gd32/02-Project-Setup-Guide/" class="dropdown-item">02-工程配置指南</a>
</li>
    </ul>
  </li>
                                    
  <li class="dropdown-submenu">
    <a href="#" class="dropdown-item">GD32V</a>
    <ul class="dropdown-menu">
            
<li>
    <a href="../../gd32v/01-Envsetup-Guide/" class="dropdown-item">01-开发环境搭建指南</a>
</li>
            
<li>
    <a href="../../gd32v/02-Project-Setup-Guide/" class="dropdown-item">02-工程配置指南</a>
</li>
    </ul>
  </li>
                                    
  <li class="dropdown-submenu">
    <a href="#" class="dropdown-item">NXP S32K</a>
    <ul class="dropdown-menu">
            
<li>
    <a href="../../s32k/01-Envsetup-Guide/" class="dropdown-item">01-开发环境搭建指南</a>
</li>
            
<li>
    <a href="../../s32k/02-Project-Setup-Guide/" class="dropdown-item">02-工程配置指南</a>
</li>
    </ul>
  </li>
                                    
  <li class="dropdown-submenu">
    <a href="#" class="dropdown-item">玄武内核模块</a>
    <ul class="dropdown-menu">
            
<li>
    <a href="../../xwko/01-XuanWuKO-Guide/" class="dropdown-item">01-上手指南</a>
</li>
    </ul>
  </li>
                                </ul>
                            </li>
                            <li class="dropdown">
                                <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">应用手册 <b class="caret"></b></a>
                                <ul class="dropdown-menu">
                                    
<li>
    <a href="../../../UserManual/00-Index/" class="dropdown-item">0.目录</a>
</li>
                                    
<li>
    <a href="../../../UserManual/01-Brief/" class="dropdown-item">1.简介</a>
</li>
                                    
<li>
    <a href="../../../UserManual/02-Basic-System-Architecture/" class="dropdown-item">2.系统基本架构</a>
</li>
                                    
<li>
    <a href="../../../UserManual/03-Build-System/" class="dropdown-item">3.构建系统</a>
</li>
                                    
<li>
    <a href="../../../UserManual/04-Boot-Flow/" class="dropdown-item">4.启动流程</a>
</li>
                                    
<li>
    <a href="../../../UserManual/05-IRQ/" class="dropdown-item">5.中断控制</a>
</li>
                                    
<li>
    <a href="../../../UserManual/06-SKD/" class="dropdown-item">6.调度器</a>
</li>
                                    
<li>
    <a href="../../../UserManual/07-Thread/" class="dropdown-item">7.线程</a>
</li>
                                    
<li>
    <a href="../../../UserManual/08-SWT/" class="dropdown-item">8.软件定时器</a>
</li>
                                    
<li>
    <a href="../../../UserManual/09-PM/" class="dropdown-item">9.电源管理</a>
</li>
                                    
<li>
    <a href="../../../UserManual/10-Lock/" class="dropdown-item">10.锁</a>
</li>
                                    
<li>
    <a href="../../../UserManual/11-Sync/" class="dropdown-item">11.同步</a>
</li>
                                    
<li>
    <a href="../../../UserManual/12-MM/" class="dropdown-item">12.内存管理</a>
</li>
                                    
<li>
    <a href="../../../UserManual/13-C-Lib/" class="dropdown-item">13.玄武C库</a>
</li>
                                </ul>
                            </li>
                            <li class="dropdown">
                                <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">Lua手册 <b class="caret"></b></a>
                                <ul class="dropdown-menu">
                                    
<li>
    <a href="../../../LuaManual/00-Index/" class="dropdown-item">0.目录</a>
</li>
                                    
<li>
    <a href="../../../LuaManual/01-Brief/" class="dropdown-item">1.简介</a>
</li>
                                    
<li>
    <a href="../../../LuaManual/02-XWXT/" class="dropdown-item">2.全局导出表</a>
</li>
                                    
  <li class="dropdown-submenu">
    <a href="#" class="dropdown-item">3.XWOS内核</a>
    <ul class="dropdown-menu">
            
<li>
    <a href="../../../LuaManual/03-XWOS/01-SDK/" class="dropdown-item">3.1.线程库</a>
</li>
            
<li>
    <a href="../../../LuaManual/03-XWOS/02-Spinlock/" class="dropdown-item">3.2.自旋锁库</a>
</li>
            
<li>
    <a href="../../../LuaManual/03-XWOS/03-Seqlock/" class="dropdown-item">3.3.顺序锁库</a>
</li>
            
<li>
    <a href="../../../LuaManual/03-XWOS/04-Mutex/" class="dropdown-item">3.4.互斥锁库</a>
</li>
            
<li>
    <a href="../../../LuaManual/03-XWOS/05-Semaphore/" class="dropdown-item">3.5.信号量库</a>
</li>
            
<li>
    <a href="../../../LuaManual/03-XWOS/06-Condition/" class="dropdown-item">3.6.条件量库</a>
</li>
            
<li>
    <a href="../../../LuaManual/03-XWOS/07-Flag/" class="dropdown-item">3.7.事件标志库</a>
</li>
            
<li>
    <a href="../../../LuaManual/03-XWOS/08-Barrier/" class="dropdown-item">3.8.线程栅栏库</a>
</li>
            
<li>
    <a href="../../../LuaManual/03-XWOS/09-Selector/" class="dropdown-item">3.9.信号选择器库</a>
</li>
            
<li>
    <a href="../../../LuaManual/03-XWOS/10-PM/" class="dropdown-item">3.10.电源管理</a>
</li>
    </ul>
  </li>
                                    
  <li class="dropdown-submenu">
    <a href="#" class="dropdown-item">4.玄武Lua函数库</a>
    <ul class="dropdown-menu">
            
<li>
    <a href="../../../LuaManual/04-XWLIB/01-Bitmap/" class="dropdown-item">4.1.位图</a>
</li>
    </ul>
  </li>
                                    
  <li class="dropdown-submenu">
    <a href="#" class="dropdown-item">5.设备栈</a>
    <ul class="dropdown-menu">
            
<li>
    <a href="../../../LuaManual/05-XWDS/01-Soc/" class="dropdown-item">5.1.SOC</a>
</li>
            
<li>
    <a href="../../../LuaManual/05-XWDS/02-GPIO/" class="dropdown-item">5.2.GPIO</a>
</li>
            
<li>
    <a href="../../../LuaManual/05-XWDS/03-UART/" class="dropdown-item">5.3.UART</a>
</li>
            
<li>
    <a href="../../../LuaManual/05-XWDS/04-SPI-Master/" class="dropdown-item">5.4.SPI Master</a>
</li>
            
<li>
    <a href="../../../LuaManual/05-XWDS/05-IIC-Master/" class="dropdown-item">5.5.IIC Master</a>
</li>
    </ul>
  </li>
                                </ul>
                            </li>
                            <li class="dropdown">
                                <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">移植笔记 <b class="caret"></b></a>
                                <ul class="dropdown-menu">
                                    
<li>
    <a href="../../../PortingNote/00-Index/" class="dropdown-item">目录</a>
</li>
                                    
<li>
    <a href="../../../PortingNote/01-Porting-Note/" class="dropdown-item">移植笔记</a>
</li>
                                    
  <li class="dropdown-submenu">
    <a href="#" class="dropdown-item">ARM-Cortex-M</a>
    <ul class="dropdown-menu">
            
<li>
    <a href="../../../PortingNote/02-ARM-Cortex-M/01-ARM-Cortex-M-Porting-Note/" class="dropdown-item">架构移植笔记</a>
</li>
            
<li>
    <a href="../../../PortingNote/02-ARM-Cortex-M/02-STM32-Porting-Note/" class="dropdown-item">STM32</a>
</li>
    </ul>
  </li>
                                    
  <li class="dropdown-submenu">
    <a href="#" class="dropdown-item">RISC-V</a>
    <ul class="dropdown-menu">
            
<li>
    <a href="../../../PortingNote/03-RISC-V/01-GD32V-Porting-Note/" class="dropdown-item">GD32V</a>
</li>
    </ul>
  </li>
                                </ul>
                            </li>
                            <li class="dropdown">
                                <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">规范 <b class="caret"></b></a>
                                <ul class="dropdown-menu">
                                    
<li>
    <a href="../../../Specification/00-Index/" class="dropdown-item">目录</a>
</li>
                                    
<li>
    <a href="../../../Specification/01-Git-Commit-Specification/" class="dropdown-item">git-commit规范</a>
</li>
                                    
<li>
    <a href="../../../Specification/02-Version-Branch-Specification/" class="dropdown-item">版本分支规范</a>
</li>
                                </ul>
                            </li>
                        </ul>

                    <ul class="nav navbar-nav ml-auto">
                        <li class="nav-item">
                            <a href="#" class="nav-link" data-toggle="modal" data-target="#mkdocs_search_modal">
                                <i class="fa fa-search"></i> 搜索
                            </a>
                        </li>
                            <li class="nav-item">
                                <a rel="prev" href="../05-atkf407core/" class="nav-link">
                                    <i class="fa fa-arrow-left"></i> 上一篇
                                </a>
                            </li>
                            <li class="nav-item">
                                <a rel="next" href="../07-Project-From-Scratch-Guide/" class="nav-link">
                                    下一篇 <i class="fa fa-arrow-right"></i>
                                </a>
                            </li>
                    </ul>
                </div>
            </div>
        </div>

        <div class="container">
            <div class="row">
                    <div class="col-md-3"><div class="navbar-light navbar-expand-md bs-sidebar hidden-print affix" role="complementary">
    <div class="navbar-header">
        <button type="button" class="navbar-toggler collapsed" data-toggle="collapse" data-target="#toc-collapse" title="Table of Contents">
            <span class="fa fa-angle-down"></span>
        </button>
    </div>

    
    <div id="toc-collapse" class="navbar-collapse collapse card bg-secondary">
        <ul class="nav flex-column">
            
            <li class="nav-item" data-level="1"><a href="#h750" class="nav-link">微行电子H750开发板上手指南</a>
              <ul class="nav flex-column">
              </ul>
            </li>
            
            <li class="nav-item" data-level="1"><a href="#1" class="nav-link">1.简介</a>
              <ul class="nav flex-column">
              </ul>
            </li>
            
            <li class="nav-item" data-level="1"><a href="#2" class="nav-link">2.开发环境</a>
              <ul class="nav flex-column">
              </ul>
            </li>
            
            <li class="nav-item" data-level="1"><a href="#3" class="nav-link">3.源码</a>
              <ul class="nav flex-column">
            <li class="nav-item" data-level="2"><a href="#bootloader" class="nav-link">Bootloader</a>
              <ul class="nav flex-column">
              </ul>
            </li>
            <li class="nav-item" data-level="2"><a href="#os" class="nav-link">玄武OS</a>
              <ul class="nav flex-column">
              </ul>
            </li>
              </ul>
            </li>
            
            <li class="nav-item" data-level="1"><a href="#4stm32cubeide" class="nav-link">4.导入工程到STM32CubeIDE</a>
              <ul class="nav flex-column">
            <li class="nav-item" data-level="2"><a href="#41" class="nav-link">4.1.导入工程</a>
              <ul class="nav flex-column">
              </ul>
            </li>
            <li class="nav-item" data-level="2"><a href="#42" class="nav-link">4.2.重新设置编译环境</a>
              <ul class="nav flex-column">
              </ul>
            </li>
              </ul>
            </li>
            
            <li class="nav-item" data-level="1"><a href="#5stm32cubemx" class="nav-link">5.STM32CubeMX配置工程</a>
              <ul class="nav flex-column">
              </ul>
            </li>
            
            <li class="nav-item" data-level="1"><a href="#6" class="nav-link">6.编译</a>
              <ul class="nav flex-column">
              </ul>
            </li>
            
            <li class="nav-item" data-level="1"><a href="#7" class="nav-link">7.调试</a>
              <ul class="nav flex-column">
            <li class="nav-item" data-level="2"><a href="#71" class="nav-link">7.1.步骤</a>
              <ul class="nav flex-column">
              </ul>
            </li>
            <li class="nav-item" data-level="2"><a href="#72" class="nav-link">7.2.技巧</a>
              <ul class="nav flex-column">
              </ul>
            </li>
            <li class="nav-item" data-level="2"><a href="#73" class="nav-link">7.3.运行过程</a>
              <ul class="nav flex-column">
              </ul>
            </li>
              </ul>
            </li>
            
            <li class="nav-item" data-level="1"><a href="#8" class="nav-link">8.示例</a>
              <ul class="nav flex-column">
              </ul>
            </li>
            
            <li class="nav-item" data-level="1"><a href="#9" class="nav-link">9.系统集成的原理</a>
              <ul class="nav flex-column">
              </ul>
            </li>
            
            <li class="nav-item" data-level="1"><a href="#10" class="nav-link">10.代码启动流程</a>
              <ul class="nav flex-column">
              </ul>
            </li>
            
            <li class="nav-item" data-level="1"><a href="#11" class="nav-link">11.功能</a>
              <ul class="nav flex-column">
              </ul>
            </li>
            
            <li class="nav-item" data-level="1"><a href="#12" class="nav-link">12.附录</a>
              <ul class="nav flex-column">
              </ul>
            </li>
        </ul>
    </div>
</div></div>
                    <div class="col-md-9" role="main">

<h1 id="h750">微行电子H750开发板上手指南</h1>
<hr />
<h1 id="1">1.简介</h1>
<p><img alt="img" src="../res/figure/WeActH750.png" title="WeActH750开发板" /></p>
<ul>
<li>MCU: STM32H750</li>
<li>更多介绍: <a href="https://item.taobao.com/item.htm?spm=a1z10.1-c-s.w4004-21792748727.8.5d7a78f2NuPkHI&amp;id=618999222275">淘宝店铺介绍</a></li>
<li>电路板目录： xwbd/WeActH750</li>
</ul>
<hr />
<h1 id="2">2.开发环境</h1>
<ul>
<li>编译集成环境可参考：<a href="../01-Envsetup-Guide/">开发环境搭建指南</a></li>
</ul>
<h1 id="3">3.源码</h1>
<p>WeActH750开发板使用外置的QSPI Flash存储代码，因此工程分为Bootloader和XuanWuOS。</p>
<h2 id="bootloader">Bootloader</h2>
<ul>
<li>描述：位于内置Flash，负责初始化QSPI Flash后跳转至QSPI Flash中执行代码；</li>
<li>仓库：<a href="https://gitee.com/xwos/WeActH750Bootloader.git">https://gitee.com/xwos/WeActH750Bootloader.git</a></li>
<li>下载：</li>
</ul>
<pre><code class="sh">git clone --recursive https://gitee.com/xwos/WeActH750Bootloader.git
cd WeActH750Bootloader
unzip project-template.zip
</code></pre>

<ul>
<li>在已有的仓库中同步代码：</li>
</ul>
<pre><code class="sh">git pull
git submodule update
</code></pre>

<h2 id="os">玄武OS</h2>
<ul>
<li>描述：XuanWuOS: 位于QSPI Flash</li>
<li>仓库：<a href="https://gitee.com/xwos/WeActH750.git">https://gitee.com/xwos/WeActH750.git</a></li>
<li>下载：</li>
</ul>
<pre><code class="sh">git clone --recursive https://gitee.com/xwos/WeActH750.git
cd WeActH750
unzip project-template.zip
</code></pre>

<ul>
<li>在已有的仓库中同步代码：</li>
</ul>
<pre><code class="sh">git pull
git submodule update
</code></pre>

<h1 id="4stm32cubeide">4.导入工程到STM32CubeIDE</h1>
<ul>
<li>工程需放在STM32CubeIDE的工作目录内（即STM32CubeIDE启动时指定的目录），
    并按照上面的命令将<code>project-template.zip</code>解压到工程目录中，
    这些文件为工程模板。</li>
</ul>
<h2 id="41">4.1.导入工程</h2>
<p>打开菜单<strong>File --&gt; Import... --&gt; General --&gt; Projects from Folder or Archive</strong></p>
<p><img alt="img" src="../res/figure/STM32CubeIDE-Import.png" title="导入工程" /></p>
<h2 id="42">4.2.重新设置编译环境</h2>
<ul>
<li>打开菜单<strong>"Project --&gt; Properties --&gt; C/C++ Build --&gt; Environment"</strong>；</li>
<li>点击<strong>"Restore Defaults"</strong>；</li>
<li>修改Debug配置的环境变量：<ul>
<li><code>WKSPC</code>:<code>../../../${ConfigName}</code></li>
<li><code>~D</code>:<code>1</code></li>
<li><code>~V</code>:<code>1</code></li>
</ul>
</li>
</ul>
<p><img alt="img" src="../res/figure/STM32CubeIDE-Project-Properties-C-Build-Env-Debug.png" title="Debug配置" /></p>
<ul>
<li>修改Release配置的环境变量：<ul>
<li><code>WKSPC</code>:<code>../../../${ConfigName}</code></li>
<li><code>~D</code>:<code>0</code></li>
<li><code>~V</code>:<code>1</code></li>
</ul>
</li>
</ul>
<p><img alt="img" src="../res/figure/STM32CubeIDE-Project-Properties-C-Build-Env-Release.png" title="Release配置" /></p>
<ul>
<li>修改Debug和Release两个配置的<strong>PATH</strong>环境变量<ul>
<li>将包含gnumcu目录的路径放在前面，保证最先被搜索；</li>
<li>删除包含STM32CubeIDE目录的所有路径。</li>
</ul>
</li>
</ul>
<h3 id="linuxpath">Linux下的环境变量<strong>PATH</strong>设置</h3>
<p><img alt="img" src="../res/figure/STM32CubeIDE-Properties-C-Build-Env-Path-Linux.png" title="Linux-Env-PATH" /></p>
<h3 id="windowspath">Windows下的环境变量<strong>PATH</strong>设置</h3>
<p><img alt="img" src="../res/figure/STM32CubeIDE-Properties-C-Build-Env-Path-Windows.png" title="Windows-Env-PATH" /></p>
<hr />
<h1 id="5stm32cubemx">5.STM32CubeMX配置工程</h1>
<p>工程中已经包含了STM32CubeMX的配置文件，可以在STM32CubeMX中打开
文件<code>xwbd/WeActH750/bm/stm32cube/cubemx/WeActH750.ioc</code>后进行修改，但需要注意：</p>
<ul>
<li>玄武OS对中断优先级的要求：</li>
</ul>
<pre><code>切换上下文的中断 &lt;= 滴答定时器的中断 &lt; 调度器服务中断
切换上下文的中断 &lt; 其他中断 &lt; 调度器服务中断
</code></pre>

<ul>
<li>NVIC设置<ul>
<li>设置3个抢占优先级位和1个子优先级位</li>
<li>SVC中断设置成<strong>最高</strong>优先级，即<strong>Preemption Priority</strong>为0；</li>
<li>PendSV中断设置成<strong>最低</strong>优先级，即<strong>Preemption Priority</strong>为7；</li>
<li>Systick中断设置成<strong>最低</strong>优先级，即<strong>Preemption Priority</strong>为7；</li>
<li>系统Fault的优先级设置为0；</li>
<li>其他中断的优先级只可在<strong>1~6</strong>之间。</li>
</ul>
</li>
</ul>
<p><img alt="img" src="../res/figure/STM32-IRQ-Priority.png" title="中断优先级" /></p>
<hr />
<h1 id="6">6.编译</h1>
<p><img alt="img" src="../res/figure/STM32CubeIDE-Build.png" title="编译" /></p>
<hr />
<h1 id="7">7.调试</h1>
<p>打开菜单<strong>Run --&gt; Debug Configurations...</strong>，根据仿真器类型，选择调试配置：</p>
<ul>
<li><code>WeActH750-openocd-daplink</code>：<strong>gdb</strong> + <strong>openocd</strong> + <strong>DAPLink调试器</strong></li>
<li><code>WeActH750-openocd-jlink</code>：<strong>gdb</strong> + <strong>openocd</strong> + <strong>JLink调试器</strong></li>
<li><code>WeActH750-jlink</code>：<strong>gdb</strong> + <strong>Segger JLink GDB Server</strong> + <strong>JLink调试器</strong></li>
<li><code>WeActH750-stlink</code>：<strong>gdb</strong> + <strong>STLink GDB Server</strong> + <strong>JLink调试器</strong></li>
</ul>
<p><img alt="img" src="../res/figure/STM32CubeIDE-Debug-Configurations.png" title="调试配置" /></p>
<h2 id="71">7.1.步骤</h2>
<ul>
<li>准备一张SD卡，格式化为FAT32文件系统；</li>
<li>将文件夹<code>xwam/example/lua</code>内的lua脚本，拷贝到SD卡内；</li>
<li>将SD卡插入开发板；</li>
<li>使用USB串口与开发板上的USART1(TX:PB14,RX:PB15)链接；</li>
<li>打开终端工具（windows可选putty、SecretCRT，Linux可选gtkterm、picocom、minicom），
    串口参数：1M波特率/8位数据/1位停止位/无奇偶校验</li>
<li>上电，并在STM32CubeIDE中启动调试，等待MCU运行到初始断点；</li>
<li>开始单步调试或连续运行调试。</li>
</ul>
<h2 id="72">7.2.技巧</h2>
<h4 id="dcache">关闭DCache</h4>
<p>ARMv7-m7内核的MCU带有Cache，常常会对定位程序BUG带来困扰。
将下面的宏开关注释掉或定义改为0后可关闭Cache。</p>
<pre><code class="C">/* xwbd/WeActH750/bm/stm32cube/cfg.h */

#define STM32CUBECFG_DCACHE             1
#define STM32CUBECFG_ICACHE             1
</code></pre>

<h4 id="_1">复位系统</h4>
<p>STM32单片机支持在调试过程中复位：可在程序入口的某个地方设定一个断点，然后让
程序持续运行，最后按一下复位按键。</p>
<h2 id="73">7.3.运行过程</h2>
<p><img alt="img" src="../res/figure/xwlua.png" title="Lua虚拟机终端" /></p>
<ul>
<li>程序入口：<code>xwbd/WeActH750/bm/main/main.c</code></li>
<li>启动流程：<ul>
<li><code>xwos_main()</code>创建一个主线程<code>main_thrd()</code>；</li>
<li><code>main_thrd()</code>依次调用各个<strong>玄武模块</strong>的<code>xxx_start()</code>函数完成对各个模块加载；</li>
<li>开始并行执行各个模块中创建的线程；</li>
</ul>
</li>
</ul>
<hr />
<h1 id="8">8.示例</h1>
<p>玄武OS中有多个示例可帮助用户快速了解API的用法：</p>
<ul>
<li>线程<ul>
<li>创建线程：<code>xwam/example/thread/create</code></li>
<li>线程睡眠：<code>xwam/example/thread/sleep</code></li>
</ul>
</li>
<li>定时器：<code>xwam/example/timer</code></li>
<li>同步<ul>
<li>信号量：<code>xwam/example/sync/semaphore</code></li>
<li>条件量：<code>xwam/example/sync/condition</code></li>
<li>事件标志：<code>xwam/example/sync/flg</code></li>
<li>线程栅栏：<code>xwam/example/sync/br</code></li>
<li>信号选择器：<code>xwam/example/sync/sel</code></li>
</ul>
</li>
<li>锁<ul>
<li>中断管理：<code>xwam/example/lock/cpuirq</code></li>
<li>自旋锁：<code>xwam/example/lock/spinlock</code></li>
<li>顺序锁：<code>xwam/example/lock/seqlock</code></li>
<li>互斥锁：<code>xwam/example/lock/mtx</code></li>
</ul>
</li>
<li>内存管理<ul>
<li>简单内存分配器：<code>xwam/example/mm/sma</code></li>
<li>内存切片分配器：<code>xwam/example/mm/memslice</code></li>
<li>伙伴算法分配器：<code>xwam/example/mm/bma</code></li>
<li>内存池：只用于比较大的内存区域的管理，例如外接的SDRAM。
    WeActH750工程已经为板载的SDRAM建立了内存池。</li>
</ul>
</li>
<li>玄武C库<ul>
<li>CRC：<code>xwam/example/xwlib/crc</code></li>
</ul>
</li>
</ul>
<p>每个示例中都有一个<code>xxx_start()</code>函数，可在<code>xwbd/WeActH750/bm/main/main.c</code>文件中的
主线程<code>main_thrd()</code>中调用这些函数启动示例，但最好一次只启动一个示例，避免冲突。</p>
<pre><code class="C">/* xwbd/WeActH750/bm/main/main.c */

xwer_t main_thrd(void * arg)
{
        ...
        example_sel_start();
        ...

        return XWOK;
}
</code></pre>

<p>实验过程中最好将lua虚拟机关闭，防止竞争串口导致输出混乱。方法是将
配置文件<code>xwbd/WeActH750/cfg/xwem.h</code>中的配置<code>XWEMCFG_vm_lua</code>改为0。</p>
<hr />
<h1 id="9">9.系统集成的原理</h1>
<ul>
<li>所有移植的第三方组件、驱动包、示例代码等都是以<strong>玄武模块</strong>独立编译成
    静态库<strong>.a</strong>，之后再将它们链接成ELF文件，再由ELF生成bin或Hex文件。</li>
<li>每个<strong>玄武模块</strong>都是一个独立的子工程，其设计思想借鉴了安卓系统的<strong>Android.mk</strong>，
    因此每个<strong>玄武模块</strong>中都有一个<code>xwmo.mk</code>文件，每个<strong>玄武模块</strong>都是独立编译的。
    每个<code>xwmo.mk</code>中定义的<strong>编译参数</strong>、<strong>头文件搜索路径</strong>只对<strong>当前玄武模块</strong>有效。</li>
<li>每个<strong>玄武模块</strong>都是一个封闭的包，外部需要使用其中头文件时需要注意头文件的依赖关系与搜索路径。
    通常，开发者需要对外提供<strong>接口头文件</strong>，这些<strong>接口头文件</strong>只能包含外部可见
    的<strong>类型定义</strong>以及<strong>API接口</strong>。例如，工程中，<code>xwbd/WeActH750/bm</code>文件夹下
    有很多<strong>玄武模块</strong>内都包含了一个名为<strong>mif.h</strong>的头文件，意思是<strong>模块接口(Module InterFace)</strong>，
    供其他模块调用。</li>
<li><strong>电路板模块</strong>(<code>xwbd/WeActH750/bm</code>)内有一个主模块<strong>main</strong>，提供<code>xwos_main()</code>函数，
    此模块功能类似于传统C语言的main()函数，为用户代码的入口。</li>
<li>玄武OS内包含了大量<strong>玄武模块</strong>，例如<code>xwcd</code>内包含了一些外设芯片的驱动，<code>xwam</code>内包含了
    示例与一些应用，<code>xwmd</code>内包含了中间件，<code>xwem</code>包含了移植的第三方开源软件。
    这些<strong>玄武模块</strong>对所有<code>xwbd</code>中的开发板理论上都是复用的。</li>
<li>有关<strong>玄武模块</strong>可以参考<a href="../../../UserManual/03-Build-System/">应用手册—构建系统</a>。</li>
</ul>
<hr />
<h1 id="10">10.代码启动流程</h1>
<p><img alt="img" src="../res/figure/stm32-boot-flow.png" title="STM32启动流程" /></p>
<ul>
<li><code>stm32cube_lowlevel_init()</code>：初始化时钟</li>
<li><code>stm32cube_init()</code>：初始化内存管理、cache、GPIO、DMA等基础设备</li>
<li><code>main_task()</code>：初始化其他设备、启动其他子线程</li>
</ul>
<hr />
<h1 id="11">11.功能</h1>
<ul>
<li>BSP<ul>
<li>STM32Cube模块：<code>xwbd/WeActH750/bm/stm32cube</code></li>
<li>STM32CubeMX配置文件：<code>xwbd/WeActH750/bm/stm32cube/cubemx/WeActH750.ioc</code></li>
<li>STM32CubeMX生成源码目录：<code>xwbd/WeActH750/bm/stm32cube/cubemx</code></li>
<li>STM32Cube适配玄武OS的源码：<code>xwbd/WeActH750/bm/stm32cube/xwac</code></li>
<li>终端UART<ul>
<li>设备：USART1</li>
<li>参数：1M波特率/8位数据/1位停止位/无奇偶校验</li>
<li>驱动<ul>
<li>驱动框架 —— 设备栈：<code>xwmd/ds/uart/dma.c</code></li>
<li>设备栈驱动：<code>xwbd/WeActH750/bm/stm32cube/xwac/xwds/uart.c</code></li>
<li>HAL库驱动：<code>xwbd/WeActH750/bm/stm32cube/cubemx/Core/Src/usart.c</code></li>
</ul>
</li>
</ul>
</li>
<li>QSPI Flash<ul>
<li>映射地址：<strong>0x90000000</strong></li>
<li>大小：<strong>8MiB</strong></li>
<li>驱动：<code>xwbd/WeActH750Bootloader/bm/stm32cube/cubemx/Core/Src/quadspi.c</code></li>
</ul>
</li>
<li>SD卡<ul>
<li>驱动：<code>xwbd/WeActH750/bm/stm32cube/cubemx/Core/Src/sdmmc.c</code></li>
</ul>
</li>
</ul>
</li>
<li>Lua<ul>
<li>版本：<strong>5.4</strong></li>
<li>源码：<code>xwem/vm/lua</code></li>
<li>适配层：<code>xwbd/WeActH750/bm/stm32cube/xwac/lua</code></li>
<li>支持REPL</li>
<li>支持从sd卡中加载脚本并执行</li>
</ul>
</li>
<li>FATFS<ul>
<li>版本：<strong>0.14</strong></li>
<li>源码：<code>xwem/filesystem/fatfs</code></li>
<li>适配层：<code>xwbd/WeActH750/bm/stm32cube/xwac/fatfs</code></li>
<li>文件系统：路径以<code>"sd:/"</code>开始</li>
</ul>
</li>
<li>libc<ul>
<li>libc.a：来源于<strong>newlib</strong></li>
<li>运行时代码：<code>xwmd/libc/newlibac</code></li>
<li>适配层代码：<code>xwbd/WeActH750/bm/stm32cube/xwac/newlib</code></li>
<li>标准输入、输出/错误：重定向至USART1</li>
<li>功能<ul>
<li><code>string.h</code>中<code>strcpy()</code>、<code>memcpy()</code>等字符串、内存操作函数；</li>
<li><code>stdio.h</code>中<code>printf()</code>、<code>sprintf()</code>等函数；</li>
<li><code>stdio.h</code>中<code>fopen()</code>、<code>fclose()</code>、<code>fwrite()</code>、<code>fread()</code>、<code>fputs()</code>、<code>fputc()</code>等文件操作函数，
    当操作SD卡的文件时，路径以<code>"sd:/"</code>开始；</li>
<li><code>stdlib.h</code>中<code>malloc()</code>、<code>realloc()</code>、<code>free()</code>等
    动态内存申请释放函数，申请的内存来源于AXI-SRAM(512KiB)，
    AXI-SRAM内存区域定义在链接脚本<code>xwbd/WeActH750/cfg/XuanWuOS.lds</code>中；</li>
<li><code>math.h</code>中定义的数学库。</li>
</ul>
</li>
</ul>
</li>
<li>C++<ul>
<li>libstdc++.a：来源于<strong>newlib</strong></li>
<li>运行时代码：<code>xwmd/cxx</code></li>
<li>适配层代码：<code>xwbd/WeActH750/bm/stm32cube/xwac/cxx</code></li>
<li>功能<ul>
<li>C++标准：gnu++17；</li>
<li>支持<code>new</code>、<code>delete</code>关键字，内存来源：AXI-SRAM(512KiB)；</li>
<li>支持STD库中的各种容器。</li>
</ul>
</li>
</ul>
</li>
</ul>
<hr />
<h1 id="12">12.附录</h1>
<ul>
<li>参考文档<ul>
<li><a href="../01-Envsetup-Guide/">开发环境搭建指南</a></li>
<li><a href="../../../UserManual/00-Index/">应用手册</a></li>
<li><a href="../../../LuaManual/00-Index/">Lua手册</a></li>
</ul>
</li>
</ul></div>
            </div>
        </div>

        <footer class="col-md-12">
            <hr>
            <p>Documentation built with <a href="https://www.mkdocs.org/">MkDocs</a>.</p>
        </footer>
        <script>
            var base_url = "../../..",
                shortcuts = {"help": 191, "next": 78, "previous": 80, "search": 83};
        </script>
        <script src="../../../js/base.js" defer></script>
        <script src="../../../search/main.js" defer></script>

        <div class="modal" id="mkdocs_search_modal" tabindex="-1" role="dialog" aria-labelledby="searchModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="searchModalLabel">搜索</h4>
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
            </div>
            <div class="modal-body">
                <p>
                    在这里所有文档：
                </p>
                <form>
                    <div class="form-group">
                        <input type="search" class="form-control" placeholder="搜索..." id="mkdocs-search-query" title="Type search term here">
                    </div>
                </form>
                <div id="mkdocs-search-results"></div>
            </div>
            <div class="modal-footer">
            </div>
        </div>
    </div>
</div><div class="modal" id="mkdocs_keyboard_modal" tabindex="-1" role="dialog" aria-labelledby="keyboardModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="keyboardModalLabel">Keyboard Shortcuts</h4>
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
            </div>
            <div class="modal-body">
              <table class="table">
                <thead>
                  <tr>
                    <th style="width: 20%;">Keys</th>
                    <th>Action</th>
                  </tr>
                </thead>
                <tbody>
                  <tr>
                    <td class="help shortcut"><kbd>?</kbd></td>
                    <td>Open this help</td>
                  </tr>
                  <tr>
                    <td class="next shortcut"><kbd>n</kbd></td>
                    <td>Next page</td>
                  </tr>
                  <tr>
                    <td class="prev shortcut"><kbd>p</kbd></td>
                    <td>Previous page</td>
                  </tr>
                  <tr>
                    <td class="search shortcut"><kbd>s</kbd></td>
                    <td>Search</td>
                  </tr>
                </tbody>
              </table>
            </div>
            <div class="modal-footer">
            </div>
        </div>
    </div>
</div>

    </body>
</html>
